home *** CD-ROM | disk | FTP | other *** search
- #include <proto/dos.h>
-
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include <ctype.h>
-
- /************************************************************************/
-
- #include "main.h"
- #include "File.h"
- #include "AdditionalDocs.h"
- #include "Includes.h"
- #include "Autodocs.h"
- #include "FormatNode.h"
-
- /************************************************************************/
-
- char *GlobalTOCFilename;
-
- /************************************************************************/
- /* */
- /* Functions to be called from FormatNode() and PrintNode() for */
- /* outputting the list of autodoc modules. */
- /* */
- /************************************************************************/
-
- struct AutodocsParameters
- {
- struct AVLStateInfo StateInfo;
- struct AutodocModuleNode *AutodocModuleNode;
- };
-
- /************************************************************************/
-
- static char *
- NextLabelAutodocs (char *PrevLabel, void *Parameters)
-
- {
- struct AutodocsParameters *Params;
-
- Params = Parameters;
- if (!PrevLabel)
- {
- AVL_InitTraversal (&AutodocModuleTree, &Params->StateInfo);
- }
-
- if ((Params->AutodocModuleNode = (struct AutodocModuleNode *) AVL_InOrder (&Params->StateInfo)))
- {
- return xstrdup(Params->AutodocModuleNode->AnyNode.Name);
- }
- return NULL;
- }
-
- /************************************************************************/
-
- static void
- PrintLinkAutodocs (void *Parameters)
-
- {
- WPrintf ("\x22%s/MAIN\x22",
- ((struct AutodocsParameters *) Parameters)->AutodocModuleNode->AutodocFileNode->LinkName);
- }
-
- /************************************************************************/
- /* */
- /* Functions to be called from FormatNode() and PrintNode() for */
- /* outputting the list of header files. */
- /* */
- /************************************************************************/
-
- struct HeadersParameters
- {
- struct AVLStateInfo StateInfo;
- struct IncludeFileNode *IncludeFileNode;
- };
-
- /************************************************************************/
-
- static char *
- NextLabelHeaders (char *PrevLabel, void *Parameters)
-
- {
- struct HeadersParameters *Params;
-
- Params = Parameters;
- if (!PrevLabel)
- {
- AVL_InitTraversal (&IncludeFileTree, &Params->StateInfo);
- }
-
- if ((Params->IncludeFileNode = (struct IncludeFileNode *) AVL_InOrder (&Params->StateInfo)))
- {
- return xstrdup(Params->IncludeFileNode->AnyNode.Name);
- }
- return NULL;
- }
-
- /************************************************************************/
-
- static void
- PrintLinkHeaders (void *Parameters)
-
- {
- WPrintf ("\x22%s/MAIN\x22",
- ((struct HeadersParameters *) Parameters)->IncludeFileNode->LinkName);
- }
-
- /************************************************************************/
- /* */
- /* Determine first letter of a name. */
- /* One of 'a'..'z' or '_' is returned. */
- /* */
- /************************************************************************/
-
- static int
- FirstLetter (struct AnyNode *AnyNode)
-
- {
- int c;
-
- c = tolower (AnyNode->Name[0]);
- if (c < 'a' || c > 'z')
- {
- c = '_';
- }
- return c;
- }
-
- /************************************************************************/
- /* */
- /* Count nodes in a tree. */
- /* */
- /************************************************************************/
-
- #define LETTERCOUNT (LetterCount-'_')
-
- /************************************************************************/
-
- static ULONG
- CountNodes (struct AVLTree *Tree, ULONG * LetterCount)
-
- {
- ULONG Count;
-
- Count = 0;
- if (Tree)
- {
- struct AVLStateInfo StateInfo;
- struct AnyNode *AnyNode;
-
- AVL_InitTraversal (Tree, &StateInfo);
- while ((AnyNode = (struct AnyNode *) AVL_InOrder (&StateInfo)))
- {
- LETTERCOUNT[FirstLetter (AnyNode)]++;
- Count++;
- }
- }
- return Count;
- }
-
- /************************************************************************/
- /* */
- /* Functions to be called from FormatNode() and PrintNode() for */
- /* outputting nodes from trees */
- /* */
- /************************************************************************/
-
- struct NodesParameters
- {
- struct AVLTree *Tree1, *Tree2;
- int StartLetter, StopLetter;
-
- struct AnyNode *AnyNode1, *AnyNode2;
- struct AVLStateInfo StateInfo1, StateInfo2;
- struct AnyNode *CurrentNode;
- };
-
- /************************************************************************/
-
- static char *
- NextLabelNodes (char *PrevLabel, void *Parameters)
-
- {
- struct NodesParameters *Params;
- char *Label;
- int c;
-
- Params = Parameters;
- if (!PrevLabel)
- {
- AVL_InitTraversal (Params->Tree1, &Params->StateInfo1);
- Params->AnyNode1 = (struct AnyNode *) AVL_InOrder (&Params->StateInfo1);
- if (Params->Tree2)
- {
- AVL_InitTraversal (Params->Tree2, &Params->StateInfo2);
- Params->AnyNode2 = (struct AnyNode *) AVL_InOrder (&Params->StateInfo2);
- }
- else
- {
- Params->AnyNode2 = NULL;
- }
- }
- else
- {
- free (PrevLabel);
- }
-
- while (Params->AnyNode1 &&
- ((c = FirstLetter (Params->AnyNode1)) < Params->StartLetter || c > Params->StopLetter))
- {
- Params->AnyNode1 = (struct AnyNode *) AVL_InOrder (&Params->StateInfo1);
- }
- while (Params->AnyNode2 &&
- ((c = FirstLetter (Params->AnyNode2)) < Params->StartLetter || c > Params->StopLetter))
- {
- Params->AnyNode2 = (struct AnyNode *) AVL_InOrder (&Params->StateInfo2);
- }
-
- if (Params->AnyNode1 || Params->AnyNode2)
- {
- if (!Params->AnyNode2)
- {
- c = -1;
- }
- else if (!Params->AnyNode1)
- {
- c = 1;
- }
- else
- {
- c = nodecmp (Params->AnyNode1, Params->AnyNode2);
- }
- if (c < 0)
- {
- if ((Params->Tree1==&AutodocNodeTree && ((struct AutodocNode *)Params->AnyNode1)->Function) ||
- (Params->Tree1==&DefinesTree && ((struct IncludeItemNode *)Params->AnyNode1)->Function))
- {
- Label=xmalloc(strlen(Params->AnyNode1->Name)+3);
- stpcpy(stpcpy(Label,Params->AnyNode1->Name),"()");
- }
- else
- {
- Label = xstrdup (Params->AnyNode1->Name);
- }
- Params->CurrentNode = Params->AnyNode1;
- Params->AnyNode1 = (struct AnyNode *) AVL_InOrder (&Params->StateInfo1);
- }
- else
- {
- if ((Params->Tree2==&AutodocNodeTree && ((struct AutodocNode *)Params->AnyNode2)->Function) ||
- (Params->Tree2==&DefinesTree && ((struct IncludeItemNode *)Params->AnyNode2)->Function))
- {
- Label=xmalloc(strlen(Params->AnyNode2->Name)+3);
- stpcpy(stpcpy(Label,Params->AnyNode2->Name),"()");
- }
- else
- {
- Label = xstrdup (Params->AnyNode2->Name);
- }
- Params->CurrentNode = Params->AnyNode2;
- Params->AnyNode2 = (struct AnyNode *) AVL_InOrder (&Params->StateInfo2);
- }
- }
- else
- {
- Label = NULL;
- }
- return Label;
- }
-
- /************************************************************************/
-
- static void
- PrintLinkNodes (void *Parameters)
-
- {
- struct NodesParameters *Params;
-
- Params = Parameters;
- if (Params->Tree1 == &AutodocNodeTree)
- {
- WPrintf ("\x22%s/%s\x22",
- ((struct AutodocNode *) Params->CurrentNode)->Entries->AutodocModuleNode->AutodocFileNode->LinkName,
- ((struct AutodocNode *)Params->CurrentNode)->Entries->RealNode->AnyNode.Name);
- }
- else
- {
- WPrintf ("\x22%s/File\x22 %lu",
- ((struct IncludeItemNode *) Params->CurrentNode)->Entries->IncludeFileNode->LinkName,
- ((struct IncludeItemNode *) Params->CurrentNode)->Entries->Line);
- }
- }
-
- /************************************************************************/
- /* */
- /* Output nodes from trees. */
- /* */
- /************************************************************************/
-
- static void
- OutputNodes (struct AVLTree *Tree1, struct AVLTree *Tree2, int StartLetter, int StopLetter)
-
- {
- struct NodesParameters Parameters;
- int *ColWidth;
-
- WPrintf ("\n");
- Parameters.Tree1 = Tree1;
- Parameters.Tree2 = Tree2;
- Parameters.StartLetter = StartLetter;
- Parameters.StopLetter = StopLetter;
- ColWidth = FormatNode (NextLabelNodes, &Parameters);
- PrintNode (NextLabelNodes, PrintLinkNodes, &Parameters, ColWidth);
- }
-
- /************************************************************************/
- /* */
- /* Create document from item tree */
- /* */
- /************************************************************************/
-
- static void
- MakeDocument (struct AVLTree *Tree1, struct AVLTree *Tree2, char *Node, char *Text)
-
- {
- ULONG LetterCount['z' - '_' + 1];
- ULONG Count;
-
- memset (LetterCount, 0, sizeof (LetterCount));
- Count = CountNodes (Tree1, LetterCount) + CountNodes (Tree2, LetterCount);
-
- WPrintf ("@NODE %s \x22%s\x22\n\n", Node, Text);
- WHeadline (Text);
-
- if (Count > 50)
- {
- struct
- {
- short FromChar;
- short ToChar;
- }
- List['z' - '_' + 1];
- int Index;
- int i;
- int Columns;
-
- Index = 0;
- for (i = 'a'; i <= 'z'; i++)
- {
- if (LETTERCOUNT[i])
- {
- List[Index].FromChar = i;
- for (Count = 0;
- Count < 50 && i <= 'z';
- Count += LETTERCOUNT[i++])
- ;
- List[Index].ToChar = --i;
- while (!LETTERCOUNT[List[Index].ToChar])
- {
- List[Index].ToChar--;
- }
- Index++;
- }
- }
- if (LETTERCOUNT['_'])
- {
- List[Index].FromChar = '_';
- List[Index++].ToChar = '_';
- }
- Columns = ((*Arguments.Width) + 3) / (5 + 3 + (*Arguments.Version >= 39));
- for (i = 0; i < Index; i++)
- {
- if (i % Columns)
- {
- WPrintf (" ");
- }
- else
- {
- WPrintf ("\n");
- }
- if (List[i].FromChar != '_')
- {
- if (List[i].FromChar == List[i].ToChar)
- {
- WPrintf ("@{\x22 %lc ", List[i].FromChar);
- }
- else
- {
- WPrintf ("@{\x22 %lc-%lc ", List[i].FromChar, List[i].ToChar);
- }
- }
- else
- {
- WPrintf ("@{\x22other");
- }
- WPrintf ("\x22 LINK \x22%s%lc\x22}", Node, List[i].FromChar);
- }
- WPrintf ("\n@ENDNODE\n");
-
- for (i = 0; i < Index; i++)
- {
- char *NodeName, *NodeNameT;
- char *NodeDesc, *NodeDescT;
-
- NodeDesc = xmalloc (strlen (Node) + 2);
- NodeDescT = stpcpy (NodeDesc, Node);
- NodeDescT[0] = List[i].FromChar;
- NodeDescT[1] = '\0';
-
- NodeName = xmalloc (strlen (Text) + 10);
- NodeNameT = stpcpy (NodeName, Text);
-
- if (List[i].FromChar == '_')
- {
- stpcpy (NodeNameT, " (other)");
- }
- else
- {
- if (List[i].FromChar == List[i].ToChar)
- {
- sprintf (NodeNameT, " (%lc)", (long) List[i].FromChar);
- }
- else
- {
- sprintf (NodeNameT, " (%lc-%lc)", (long) List[i].FromChar, (long) List[i].ToChar);
- }
- }
- WPrintf ("@NODE \x22%s\x22 \x22%s\x22\n\n", NodeDesc, NodeName);
- WHeadline (NodeName);
- free (NodeName);
- free (NodeDesc);
-
- OutputNodes (Tree1, Tree2, List[i].FromChar, List[i].ToChar);
-
- WPrintf ("@ENDNODE\n");
- }
- }
- else
- {
- OutputNodes (Tree1, Tree2, '_', 'z');
- WPrintf ("@ENDNODE\n");
- }
- }
-
- /************************************************************************/
- /* */
- /* Create the global table of contents */
- /* */
- /************************************************************************/
-
- void
- WriteGlobalTOC (void)
-
- {
- if (Arguments.Master)
- {
- puts("\n*** Creating global table of contents ***");
- WOpen (CURRENTDIR, Arguments.Master);
- GlobalTOCFilename=Arguments.FullPath ? xstrdup(WriteFilename) : Arguments.Master;
- WriteHeader (WriteFilename, NULL);
-
- WPrintf ("\n@NODE MAIN \x22Global table of contents\x22\n\n");
- WHeadline ("Table of contents");
- WPrintf ("%s",
- "\n"
- " @{\x22 autodoc documents \x22 LINK Autodocs}\n"
- " @{\x22 function names \x22 LINK Functions}\n"
- "\n"
- " @{\x22 header files \x22 LINK Headers}\n"
- " @{\x22 structs/unions \x22 LINK StructsUnions}\n"
- " @{\x22 #defines \x22 LINK Defines}\n"
- " @{\x22 typedefs \x22 LINK Typedefs}\n"
- "@ENDNODE\n");
-
- {
- struct AutodocsParameters Parameters;
- int *ColWidth;
-
- WPrintf ("@NODE Autodocs \x22" "Autodoc Documents\x22\n\n");
- WHeadline ("Autodoc documents");
- WPrintf ("\n");
- ColWidth = FormatNode (NextLabelAutodocs, &Parameters);
- PrintNode (NextLabelAutodocs, PrintLinkAutodocs, &Parameters, ColWidth);
- WPrintf ("@ENDNODE\n");
- }
-
- MakeDocument (&AutodocNodeTree, NULL, "Functions", "Autodoc entries");
-
- {
- struct HeadersParameters Parameters;
- int *ColWidth;
-
- WPrintf ("\n@NODE Headers \x22Header files\x22\n\n");
- WHeadline ("Header files");
- WPrintf ("\n");
- ColWidth = FormatNode (NextLabelHeaders, &Parameters);
- PrintNode (NextLabelHeaders, PrintLinkHeaders, &Parameters, ColWidth);
- WPrintf ("@ENDNODE\n");
- }
-
- MakeDocument (&StructureTree, &UnionTree, "StructsUnions", "structs/unions");
- MakeDocument (&DefinesTree, NULL, "Defines", "#defines");
- MakeDocument (&TypedefTree, NULL, "Typedefs", "typedefs");
-
- WClose ();
- }
- }
-
- /************************************************************************/
- /* */
- /* Output the xref for an include item tree */
- /* */
- /************************************************************************/
-
- static void
- DoIncludeXRef (struct AVLTree *Tree, ULONG Type)
-
- {
- struct AVLStateInfo StateInfo;
- struct IncludeItemNode *IncludeItemNode;
-
- AVL_InitTraversal (Tree, &StateInfo);
- while ((IncludeItemNode = (struct IncludeItemNode *) AVL_InOrder (&StateInfo)))
- {
- struct IncludeItemNodeNode *IncludeItemNodeNode;
-
- for (IncludeItemNodeNode = IncludeItemNode->Entries;
- IncludeItemNodeNode;
- IncludeItemNodeNode = IncludeItemNodeNode->Next)
- {
- WPrintf ("\x22%s\x22 \x22%s\x22 %lu %lu\n",
- IncludeItemNode->AnyNode.Name,
- IncludeItemNodeNode->IncludeFileNode->LinkName,
- IncludeItemNodeNode->Line,
- ((Type == 8 && IncludeItemNode->Function) ? 4 : Type));
- }
- }
- }
-
- /************************************************************************/
- /* */
- /* Write the crossreference file */
- /* */
- /************************************************************************/
-
- void
- WriteXRef (void)
-
- {
- if (Arguments.XREF)
- {
- struct AVLStateInfo StateInfo;
- struct AutodocNode *AutodocNode;
-
- puts("\n*** Creating crossreference file ***");
-
- WOpen (CURRENTDIR, Arguments.XREF);
- WPrintf ("/*\n");
- WriteHeader (WriteFilename, NULL);
- WPrintf ("*/\n\nXREF:\n");
-
- AVL_InitTraversal (&AutodocNodeTree, &StateInfo);
- while ((AutodocNode = (struct AutodocNode *) AVL_InOrder (&StateInfo)))
- {
- struct AutodocNodeNode *AutodocNodeNode;
-
- for (AutodocNodeNode = AutodocNode->Entries;
- AutodocNodeNode;
- AutodocNodeNode = AutodocNodeNode->Next)
- {
- ULONG Type;
-
- if (AutodocNode->Function)
- Type = 1;
- else if (strcmp (AutodocNodeNode->AutodocModuleNode->AnyNode.Name, "SAD"))
- Type = 8;
- else
- Type = 2;
-
- if (AutodocNodeNode->RealNode == AutodocNodeNode)
- {
- WPrintf ("\x22%s\x22 \x22%s\x22 0 %lu\n",
- AutodocNodeNode->AnyNode.Name,
- AutodocNodeNode->AutodocModuleNode->AutodocFileNode->LinkName,
- Type);
- }
- else
- {
- WPrintf ("/* $%$%ALIAS%$%$: \x22%s\x22 \x22%s\x22 \x22%s\x22 0 %lu */\n",
- AutodocNodeNode->AnyNode.Name,
- AutodocNodeNode->RealNode->AnyNode.Name,
- AutodocNodeNode->RealNode->AutodocModuleNode->AutodocFileNode->LinkName,
- Type);
- }
- }
- }
-
- DoIncludeXRef (&DefinesTree, 8);
- DoIncludeXRef (&StructureTree, 5);
- DoIncludeXRef (&UnionTree, 5);
- DoIncludeXRef (&TypedefTree, 7);
-
- WPrintf ("#\n");
-
- WClose();
- }
- }
-